package com.hsogoo.avatar.control;

import java.util.concurrent.TimeUnit;

import com.google.common.util.concurrent.RateLimiter;

/**
 * Created by za-huangsaigang on 2018/10/30.
 */
public class RateLimiterControl implements LimitControl {

    private RateLimiter rateLimiter;

    public RateLimiterControl(double limit) {
        this.rateLimiter = RateLimiter.create(limit);
    }

    @Override
    public double acquire() {
        return rateLimiter.acquire();
    }

    @Override
    public boolean tryAcquire() {
        return rateLimiter.tryAcquire();
    }

    @Override
    public boolean tryAcquire(long timeout) {
        return rateLimiter.tryAcquire(timeout, TimeUnit.MICROSECONDS);
    }
}
